LEADTOOLS Image File Support (Leadtools.Codecs assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
ReadTagsWithOffsets(String,Int32,Int64[]) Method
See Also 
Leadtools.Codecs Namespace > RasterCodecs Class > ReadTagsWithOffsets Method : ReadTagsWithOffsets(String,Int32,Int64[]) Method



fileName
A System.String containing the input file name.
pageNumber
1-based index of the page from which to read the tags.
offsets
An array that contains the offests for each tag.
fileName
A System.String containing the input file name.
pageNumber
1-based index of the page from which to read the tags.
offsets
An array that contains the offests for each tag.
Reads all the tags stored in a TIFF file, along with the offsets for each tag.

Syntax

Visual Basic (Declaration) 
Overloads Public Function ReadTagsWithOffsets( _
   ByVal fileName As String, _
   ByVal pageNumber As Integer, _
   ByRef offsets As Long() _
) As RasterCollection(Of RasterTagMetadata)
Visual Basic (Usage)Copy Code
Dim instance As RasterCodecs
Dim fileName As String
Dim pageNumber As Integer
Dim offsets As Long()
Dim value As RasterCollection(Of RasterTagMetadata)
 
value = instance.ReadTagsWithOffsets(fileName, pageNumber, offsets)
C# 
public RasterCollection<RasterTagMetadata> ReadTagsWithOffsets( 
   string fileName,
   int pageNumber,
   out long[] offsets
)
C++/CLI 
public:
RasterCollection<RasterTagMetadata^>^ ReadTagsWithOffsets( 
   String^ fileName,
   int pageNumber,
   [Out] array<int64> offsets
) 

Parameters

fileName
A System.String containing the input file name.
pageNumber
1-based index of the page from which to read the tags.
offsets
An array that contains the offests for each tag.

Return Value

A collection of Leadtools.RasterTagMetadata containing all the tags found in the file. If the file does not contain any tags, an empty collection will be returned. If the file format does not support tags, an exception will be thrown.

Example

This example will load all the tags, with their offsets, from a file.

Visual BasicCopy Code
Private Shared Sub ReadTagsWithOffsetsExample()
   ' Prompt the user for an image file
   Dim imageFileName As String = PromptForFileName()
   ' Initialize LEADTOOLS
   Using codecs As New RasterCodecs()
      ' Get the file format
      Dim format As RasterImageFormat

      Using info As CodecsImageInfo = codecs.GetInformation(imageFileName, False)
         format = info.Format
      End Using

      ' Load the tags, with their offsets
      Dim tags As RasterCollection(Of RasterTagMetadata) = Nothing
      Dim offsets As Long() = Nothing
      If RasterCodecs.TagsSupported(format) Then
         tags = codecs.ReadTagsWithOffsets(imageFileName, 1, offsets)
      End If

      Dim txtFileName As String = Path.Combine( _
         Path.GetDirectoryName(imageFileName), _
         Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt")

      Using writer As StreamWriter = File.CreateText(txtFileName)
         ' Write the tags
         WriteTags(writer, "Tags", tags, offsets)
      End Using

      ' Show the text file we created
      System.Diagnostics.Process.Start(txtFileName)
   End Using
End Sub

Private Shared Sub WriteTags(ByVal writer As StreamWriter, ByVal name As String, ByVal tags As RasterCollection(Of RasterTagMetadata), ByVal offsets As Long())
   writer.WriteLine("{0}:", name)

   If Not IsNothing(tags) Then
      Dim x As Integer = 0
      For Each tag As RasterTagMetadata In tags
         writer.WriteLine("Id: 0x{0}, offset: {1}", tag.Id.ToString("X"), offsets(x))
         x = x + 1
      Next
   Else
      writer.WriteLine("Not supported")
   End If

   writer.WriteLine()
End Sub
C#Copy Code
public void ReadTagsWithOffsetsExample()
{
   // Prompt the user for an image file
   string imageFileName = PromptForFileName();
   // Initialize LEADTOOLS
   using (RasterCodecs codecs = new RasterCodecs())
   {
      // Get the file format
      RasterImageFormat format;

      using (CodecsImageInfo info = codecs.GetInformation(imageFileName, false))
      {
         format = info.Format;
      }

      // Load the tags, with their offsets
      RasterCollection<RasterTagMetadata> tags = null;
      long[] offsets = null;
      if (RasterCodecs.TagsSupported(format))
         tags = codecs.ReadTagsWithOffsets(imageFileName, 1, out offsets);

      string txtFileName = Path.Combine(
         Path.GetDirectoryName(imageFileName),
         Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt");

      using (StreamWriter writer = File.CreateText(txtFileName))
      {
         // Write the tags
         WriteTags(writer, "Tags", tags, offsets);
      }

      // Show the text file we created
      System.Diagnostics.Process.Start(txtFileName);
   }
}

private static void WriteTags(StreamWriter writer, string name, RasterCollection<RasterTagMetadata> tags, long[] offsets)
{
   writer.WriteLine("{0}:", name);

   if (tags != null)
   {
      int x = 0;
      foreach (RasterTagMetadata tag in tags)
      {
         writer.WriteLine("Id: 0x{0}, offset: {1}", tag.Id.ToString("X"), offsets[x]);
         x++;
      }
   }
   else
   {
      writer.WriteLine("Not supported");
   }

   writer.WriteLine();
}
SilverlightCSharpCopy Code
SilverlightVBCopy Code

Remarks

To read a specific tag stored in a file, use ReadTag(String,Int32,Int32) and to enumerate all the tag ids (but not the data) stored in a file use EnumTags(String,Int32).

This method will throw an exception if the file format does not support tags. To check if a file format supports tags, use RasterCodecs.TagsSupported. You can also automatically load all the tags stored in a file during a load operation by setting the CodecsLoadOptions.Tags property to true. The tags data will be stored in the result image RasterImage.Tags collection.

To load all the tags stored in a stream containing the image data, use ReadTags(Stream,Int32).

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also